<template>
    <ul>
        <li class="orderLi" v-for="(data,index) in list" :key="data.id">
            <div class="listId">
                订单号：{{data.id}}  <span class="orderTime">{{data.create_time}}</span>
                <div class="operation">
                    <template v-if="data.invoice_company && data.invoice_no">
                        <a :href="'http://www.kuaidi100.com/chaxun?com='+expressName(data.invoice_company)+'&nu='+data.invoice_no" target="_blank">查看物流</a>
                    </template>
                    <!--<span class="delOrder" @click="del(index)">删除订单</span>-->
                </div>
            </div>
            <div class="goodsInfo">
                <div class="goods">
                    <div class="goodsLi" v-for="item in data.orderGoods">
                        <router-link :to="'/commodity-details?id='+item.goods.goods_id">
                            <img :src="url(item.goods.thumb.url, '240x240')" alt="">
                            <p>{{item.goods.name}} {{item.goodsAttr?'(规格：'+item.goodsAttr.name+')':''}}</p>
                            <div><span>{{item.number}}</span><span>￥{{item.goods.price}}</span></div>
                        </router-link>
                    </div>
                    <p v-if="!data.orderGoods" style="text-align: center;line-height: 160px;">线下支付</p>
                </div>
                <div class="orderMoney">
                    <div>
                        <p>总价 <span>￥{{data.total_fee}}</span></p>
                        <p>含运费 <span>￥{{data.shipping_fee}}</span></p>
                    </div>

                </div>
                <div class="orderState">
                    <!--<i class="glyphicon glyphicon-ok-circle"></i>-->
                    {{data.status | state}}
                </div>
            </div>
            <div class="orderAddress" v-if="data.address">
                <p>收货信息</p>
                <p>收货姓名：{{data.address.consignee}}</p>
                <p>联系电话：{{data.address.mobile}}</p>
                <p>收货地址：{{data.address.provinceRegion.name}}{{data.address.cityRegion.name}}{{data.address.districtRegion.name}}
                    {{data.address.address}}</p>
                <p>备注信息：{{data.post_text}}</p>
            </div>
            <button class="btn btn-primary" v-if="data.status==6&&!data.attachment.ifComment" @click="comment(data.id)">评论</button>
            <button class="btn btn-primary" v-if="data.status==4" @click="confirmReceipt(data)">确认收货</button>
        </li>
        <load-more @load="loadMore">
            <template v-if="ifMore"><img src="../../images/loading.gif" alt="加载中" width="150"></template>
            <template v-else>没有更多</template>
        </load-more>
    </ul>
</template>
<script>
require('./order.css');
var loadMore=require('./loadMore.vue');
var listCore=require('./list/list-core');


var COMPANY_SITE={
    'SF' : 'shunfeng',
    'STO' : 'shentong',
    'YD' : 'yunda',
    'ZTO' : 'zhongtong',
    'YTO' : 'yuantong',
    'HTKY' : 'huitongkuaidi',
    'AJ' : 'anjie',
    'ANE' : '安能物流',
    'AXD' : 'anxindakuaixi',
    'BQXHM' : '北青小红帽',
    'BFDF' : 'baifudongfang',
    'BTWL' : 'huitongkuaidi',
    'CCES' : 'CCES快递',
    'CITY100' : '城市100',
    'COE' : 'coe',
    'CSCY' : '长沙创一',
    'DBL' : 'debangwuliu',
    'DSWL' : 'dsukuaidi',
    'DTWL' : 'datianwuliu',
    'EMS' : 'EMS',
    'FAST' : 'kuaijiesudi',
    'FEDEX' : 'FEDEX联邦(国内件）',
    'FEDEX_GJ' : 'FEDEX联邦(国际件）',
    'FKD' : 'feikangda',
    'GDEMS' : 'guangdongyouzhengwuliu',
    'GSD' : 'gongsuda',
    'GTO' : 'guotongkuaidi',
    'GTSD' : '高铁速递',
    'HFWL' : '汇丰物流',
    'HHTT' : 'tiantian',
    'HLWL' : 'hengluwuliu',
    'HOAU' : 'tiandihuayu',
    'hq568' : '华强物流',
    'HXLWL' : 'huaxialongwuliu',
    'HYLSD' : '好来运快递',
    'JGSD' : 'jinguangsudikuaijian',
    'JIUYE' : '九曳供应链',
    'JJKY' : 'jjwl',
    'JLDT' : 'jialidatong',
    'JTKD' : '捷特快递',
    'JXD' : 'jixianda',
    'JYKD' : 'jykd',
    'JYM' : 'jymwl',
    'JYWL' : 'jiayiwuliu',
    'KYWL' : '跨越物流',
    'LB' : 'longbanwuliu',
    'LHT' : 'lianhaowuliu',
    'MHKD' : 'minghangkuaidi',
    'MLWL' : '明亮物流',
    'NEDA' : 'ganzhongnengda',
    'PADTF' : '平安达腾飞快递',
    'QCKD' : 'quanchenkuaidi',
    'QFKD' : 'quanfengkuaidi',
    'QRT' : 'quanritongkuaidi',
    'RFD' : 'rufengda',
    'SAD' : 'saiaodi',
    'SAWL' : '圣安物流',
    'SBWL' : '盛邦物流',
    'SDWL' : '上大物流',
    'SFWL' : 'shengfeng',
    'SHWL' : 'shenghuiwuliu',
    'ST' : '速通物流',
    'STWL' : '速腾快递',
    'SURE' : 'sue',
    'TSSTO' : '唐山申通',
    'UAPEX' : 'quanyikuaidi',
    'UC' : 'youshuwuliu',
    'WJWL' : 'wanjiawuliu',
    'WXWL' : 'wxwl',
    'XBWL' : 'xinbangwuliu',
    'XFEX' : 'xinfengwuliu',
    'XYT' : '希优特',
    'XJ' : '新杰物流',
    'YADEX' : 'yad',
    'YCWL' : 'yuanchengwuliu',
    'YDH' : '义达国际物流',
    'YFEX' : 'yuefengwuliu',
    'YFHEX' : '原飞航物流',
    'YFSD' : 'yafengsudi',
    'YTKD' : 'yuntongkuaidi',
    'YXKD' : '亿翔快递',
    'YZPY' : 'youzhengguonei',
    'ZENY' : '增益快递',
    'ZHQKD' : '汇强快递',
    'ZJS' : 'zhaijisong',
    'ZTE' : '众通快递',
    'ZTKY' : 'zhongtiekuaiyun',
    'ZTWL' : '中铁物流',
    'ZYWL' : 'zhongyouwuliu',
    'AMAZON' : '亚马逊物流',
    'SUBIDA' : '速必达物流',
    'RFEX' : '瑞丰速递',
    'QUICK' : '快客快递',
    'CJKD' : '城际快递',
    'CNPEX' : 'zhongyouwuliu',
    'HOTSCM' : '鸿桥供应链',
    'HPTEX' : '海派通物流公司',
    'AYCA' : '澳邮专线',
    'PANEX' : '泛捷快递',
    'PCA' : 'PCA Express',
    'UEQ' : 'UEQ Express',
}

module.exports={
    components:{
        loadMore:loadMore,
    },
    mixins:[listCore],
    data:function () {
        return{
//            whichList:'orders',
            autoLoad: false,
            request: function (params, status) {
                var item = $.extend({}, params, status);
                return JxSdk.order.list(null,0,item.page);
            },
        }
    },
    watch:{
      list:{
          handler:function () {
              this.$emit('updata',this.breviary.total);
          },
          deep:true,
      }
    },
    filters:{
        state:function (val) {
            var st={
                '0':'待支付',
                '1':'已取消订单',
                '2':'等待发货',
                '3':'备货中',
                '4':'待确认收货',
                '6':'已确认收货',
            };
            return st[val];
        }
    },
    methods:{
        loadMore:function () {//滚动刷新
                this.loadNextPage();
        },
        del:function (index) {
            this.list.splice(index,1);
        },
        comment:function (id) {//评论
            this.$router.push('/comment?id='+id);
        },
        confirmReceipt:function (item) {//确认收货
            if(confirm('是否确认收货')){
                JxSdk.order.confirm(item.id);
                item.status=6;
            }
        },
        expressName: function(code) {
            return COMPANY_SITE[code];
        },
        url:JxSdk.img.getUrl,
    },
    mounted:function () {
        var _self = this;
        JxSdk.ready(function () {
            _self.load()
        })
    }
}
</script>